package com.lyl.serviceorder.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lyl.commonutils.R;
import com.lyl.serviceorder.entity.Order;
import com.lyl.serviceorder.service.OrderService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.Banner;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author 雷艳玲
 * @since 2022-06-25
 */
@RestController
@RequestMapping("/serviceorder/order")
public class OrderController {
    @Autowired
    OrderService orderService;



    @GetMapping("/getOrderCountByDay/{date}")
    R getOrderCountByDay(@PathVariable("date") String date) {
        double prices = orderService.sumPriceByDate(date);
        return R.ok().data("count", prices);
    }

    @ApiOperation(value = "获取订单列表")
    @PostMapping("{page}/{limit}")
    public R pageQuery(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Long limit,

            @ApiParam(name = "courseQuery", value = "查询对象", required = false)
                    Order courseQuery){

        Page<Order> pageParam = new Page<>(page, limit);

        orderService.pageQuery(pageParam, courseQuery);
        List<Order> records = pageParam.getRecords();

        long total = pageParam.getTotal();

        return  R.ok().data("total", total).data("rows", records);
    }
}

